package Multiplexer;


import java.util.Hashtable;

import pressepapier.PressePapierSystem;
import pressepapier.PressePapierText;

import Debog.Debog;
import Memento.Memento;
import Memento.Memoire;
import Nuplet.Pair;
import TasDePapiers.TasDePapiers;
import editeur.EditeurEtoile;
import editeur.EditeurPlus;
import editeurimpl.Buffer;
import editeurimpl.PressePapier;
import editeurimpl.Selection;


public class Multiplexer extends Debog implements EditeurEtoile {

        private Hashtable<Integer,EditeurPlus> editor;
        private int current;
        public Multiplexer() {
                 editor = new Hashtable<Integer,EditeurPlus>();
        }
        public void newEditor(int id){
                
                Buffer buffer=new Buffer();
                Selection sel=new Selection();
                
                PressePapier pressepapier =new PressePapierSystem();
                pressepapier.setdebog(this);
                
                Memoire undoredo=new Memoire();
                undoredo.setdebog(this);
                
                TasDePapiers tas=new PressePapierText();
                tas.setdebog(this);
                
                EditeurPlus e=new EditeurPlusImpl(sel, buffer, pressepapier,undoredo,tas);
                e.setdebog(this);
                
                editor.put(id, e);
                
        }
        public void setcurrent(int i){
                current=i;
        }
        public void unsetEditor(){
                editor.remove(current);
        }
        public int coller(int pos) {
                return editor.get(current).coller(pos);
        }
        public void copier() {
                editor.get(current).copier();
        }
        public void effacer() {
                editor.get(current).effacer();
        }
        public boolean enregistrer(String file) {
                return editor.get(current).enregistrer(file);   
        }
        public String get_buffer_contenu() {
                return editor.get(current).get_buffer_contenu();
        }
        public int get_buffer_taille() {
                return editor.get(current).get_buffer_taille();
        }
        public String get_selection_contenu() {
                return editor.get(current).get_selection_contenu();
        }
        public int get_selection_deb() {
                return editor.get(current).get_selection_deb();
        }
        public int get_selection_fin() {
                return editor.get(current).get_selection_fin();
        }
        public String gettitre() {
                return editor.get(current).gettitre();
        }
        public void inserer(String t,int pos) {
                editor.get(current).inserer(t,pos);             
        }
        public boolean ouvrir(String file) {
                if (file==null) return false;
           return editor.get(current).ouvrir(file);             
        }
        public void selectionner(int deb, int fin) {
                editor.get(current).selectionner(deb,fin);
        }
        public boolean selection_active() {
                return editor.get(current).selection_active();
        }
        public void retenir(Memento m){
                editor.get(current).retenir(m);
        }
        public void annuler() {
                editor.get(current).annuler();
        }
        public void refaire() {
                editor.get(current).refaire();
        }
        public int get_selection_size() {
                return editor.get(current).get_selection_size();
        }
        public void selection_desactiver() {
                editor.get(current).selection_desactiver();
        }
        public boolean trouver(String mot, int deb) {
                return editor.get(current).trouver(mot, deb);
        }
        public boolean trouver_en_arriere(String mot, int deb) {
                return editor.get(current).trouver_en_arriere(mot, deb);
        }
        public void select_line(int pos) {
                editor.get(current).select_line(pos);
        }
        public int IndexToLineNumber(int pos) {
                return editor.get(current).IndexToLineNumber(pos);
        }
        public int LineNumberToIndex(int pos) {
                return editor.get(current).LineNumberToIndex(pos);
        }
        public int text_popAll(int pos) {
                return editor.get(current).text_popAll(pos);
        }
        public void text_push() {
                editor.get(current).text_push();                
        }
		public boolean recharger() {
			return editor.get(current).recharger();
		}
		public boolean recharger(String encodage) {
			return editor.get(current).recharger(encodage);
		}
		public void clean_pusher() {
			 editor.get(current).clean_pusher();      
		}
		public int debut_ligne(int pos) {
			return editor.get(current).debut_ligne(pos);
		}
		public int fin_ligne(int pos) {
			return editor.get(current).fin_ligne(pos);
		}
		public Pair<Integer, Integer> IndexToCoord(int index) {
			return editor.get(current).IndexToCoord(index);
		}

}